﻿using System;
using System.Net;
using System.Xml;
using System.IO;

namespace DragDraw.Service
{
    public class ServerConfiguration
    {
        private static ServerConfiguration m_instance = new ServerConfiguration();
        public static ServerConfiguration Instance { get { return m_instance; } }

        private ServerConfiguration()
        {
            XmlReader xr = XmlReader.Create("ClientConfig.xml");
            while (xr.Read())
            {
                if (xr.NodeType == XmlNodeType.Element &&
                    xr.Name == "Config")
                {
                    xr.MoveToFirstAttribute();
                    string key = xr.Value;
                    xr.MoveToNextAttribute();
                    switch(key)
                    {
                        case "BaseUrl":
                            BaseUrl = xr.Value;
                            break;
                        case "BasicServiceName":
                            BasicServiceAddress = BaseUrl + xr.Value;
                            break;
                        case "DuplexServiceName":
                            DuplexServiceAddress = BaseUrl + xr.Value;
                            break;
                        case "FileFolder":
                            FileFolderUrl = BaseUrl + xr.Value;
                            break;
                        case "WidgetFolder":
                            WidgetFolderUrl = BaseUrl + xr.Value;
                            break;
                    }
                }
            }
        }

        public string BasicServiceAddress { get; private set; }

        public string DuplexServiceAddress { get; private set; }

        public string BaseUrl { get; private set; }

        public string FileFolderUrl { get; private set; }

        public string WidgetFolderUrl { get; private set; }
    }
}
